#include <QQuickItem>
#include <QColor>

class MyCppItem : public QQuickItem
{
    Q_OBJECT
    Q_PROPERTY(int xPos READ xPos WRITE setXPos NOTIFY xPosChanged)
    Q_PROPERTY(int yPos READ yPos WRITE setYPos NOTIFY yPosChanged)
    Q_PROPERTY(int itemWidth READ itemWidth WRITE setItemWidth NOTIFY itemWidthChanged)
    Q_PROPERTY(int itemHeight READ itemHeight WRITE setItemHeight NOTIFY itemHeightChanged)
    Q_PROPERTY(QColor itemColor READ itemColor WRITE setItemColor NOTIFY itemColorChanged)
    QML_ELEMENT

public:
    explicit MyCppItem(QQuickItem *parent = nullptr);

    // 属性访问器
    int xPos() const;
    void setXPos(int x);

    int yPos() const;
    void setYPos(int y);

    int itemWidth() const;
    void setItemWidth(int width);

    int itemHeight() const;
    void setItemHeight(int height);

    QColor itemColor() const;
    void setItemColor(const QColor &color);

signals:
    void xPosChanged();
    void yPosChanged();
    void itemWidthChanged();
    void itemHeightChanged();
    void itemColorChanged();

private:
    int m_xPos = 0;
    int m_yPos = 0;
    int m_itemWidth = 100;
    int m_itemHeight = 100;
    QColor m_itemColor = Qt::blue;
};
